<template>
  <div id="app">
    <open-header>
      <div slot="right">
        <user-info v-if="!noUser" :userStatus="noUser"></user-info>
      </div>
    </open-header>
    <div class="open-body">
      <div class="container body-container">
        <side-menu :routes="routes"></side-menu>
        <div class="panel">
          <router-view></router-view>
        </div>
      </div>
    </div>
    <div class="no_access" v-if="showNoAccess">
      <div class="float-box-alert">
        <div class="content">您没有此平台的使用权限</div>
        <div class="form-operation">
          <button class="form-btn btn-primary" @click="toLogin">好的</button>
        </div>
      </div>
    </div>
    <open-footer></open-footer>
    <float-box></float-box>
  </div>
</template>

<script>
  import Header from 'open-vue-components/src/components/layout/Header'
  import UserInfo from '../UserInfo'
  import Footer from 'open-vue-components/src/components/layout/Footer'
  import SideMenu from 'open-vue-components/src/components/navigator/SideMenu'
  import Pagination from 'open-vue-components/src/components/navigator/Pagination'
  import FloatBox from '../controls/FloatBox'

  import 'style/common/reset.less'

  export default {
    name: 'app',
    data(){
      return {
        routes: [{
          name: 'columns',
          link: { name: 'Columns' },
          displayName: '专栏管理',
          icon: '&#xe601'
        }, {
          name: 'expert',
          link: { name: 'Expert' },
          displayName: '电台设置',
          icon: '&#xe604'
        }],
        showNoAccess: false
      }
    },props:['noUser'],
    components: {
      'open-header': Header,
      'open-footer': Footer,
      'float-box': FloatBox,
      'side-menu': SideMenu,
      'pagination': Pagination,
      'user-info':UserInfo
    },
    created() {
      this.$store.dispatch('loadUserDetail').then(() =>{
        if (this.$store.state.user.status !== 1) {
          this.showNoAccess = true;
        }
      }, () =>{
        location.href = `http://reg.163.com/Logout.jsp?url=${location.origin}/login.html`;
      });
    },
    methods: {
      toLogin(){
        location.href = `http://reg.163.com/Logout.jsp?url=${location.origin}/login.html`;
      }
    }
  };
</script>

<style rel="stylesheet/less" lang="less">
  body {
    min-width: 1180px;
  }
  .header{
    .logo{
      width: 393px;
      background: url(../../assets/logo.png) left center no-repeat;
    }
  }
  .container {
    width: 1180px;
    margin: auto;
    position: relative;
    .main {
      box-sizing: border-box;
      width: 987px;
      margin-left: 195px;
      padding-top: 27px;
      padding-left: 26px;
      padding-bottom: 40px;
    }
  }

  .body-container {
  }

  .panel {
    box-sizing: border-box;
    min-height: 760px;
    width: 987px;
    margin-left: 195px;
    padding-top: 27px;
    padding-left: 26px;
    padding-bottom: 40px;
  }

  .router-enter {
    transform: translate3d(50px, 0, 0);
    opacity: 0;
  }

  .router-enter-active {
    animation: router-in .5s;
  }

  .router-leave-active {
    position: absolute;
    animation: router-out .5s;
  }

  a {
    color: #0d8337;
    transition: color .5s;
  }

  @keyframes router-in {
    from {
      transform: translate3d(25px, 0, 0);
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes router-out {
    to {
      transform: translate3d(0, 0, 0) scale(.95);
      opacity: 0;
    }
  }

  .form-operation {
    text-align: center;
    white-space: nowrap;
    .form-btn {
      display: inline-block;
      min-width: 144px;
      margin: 0 20px;
      border: 1px solid;
      border-radius: 5px;
      background: transparent;
      color: #2e9057;
      font-size: 14px;
      line-height: 38px;
      outline: none;
      transition: .25s;
      cursor: pointer;
      &:hover {
        background: #f4fff9;
      }
      &:active {
        transition: .1s;
        background: inherit;
      }
      &.btn-primary {
        background: #2e9057;
        color: #fff;
        &:hover {
          background: #4da672;
        }
        &:active {
          background: #2e9057;
        }
      }
      &.btn-disable {
        background: #f0f0f0;
        border-color: #ddd;
        color: #999;
        cursor: no-drop;
        &:hover, &:active {
          background: #f0f0f0;
        }
      }
    }
  }

  .no_access {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    transition: .5s;
    pointer-events: all;
    &:before {
      content: ' ';
      display: block;
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      background: rgba(0, 0, 0, 0.5);
      opacity: 1;
      pointer-events: all;
      transition: .5s;
    }
  }

  .float-box-alert, .float-box-confirm {
    box-sizing: border-box;
    position: absolute;
    max-width: 480px;
    left: 50%;
    bottom: 50%;
    padding: 24px;
    background: rgba(255, 255, 255, .9);
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transform: translateX(-50%) translateY(25%);
    .content {
      display: inline-block;
      min-height: 48px;
      padding-bottom: 32px;
      color: #666;
      font-size: 16px;
      text-align: left;
    }
  }
</style>
